package day4;

import java.lang.reflect.Field;
import java.util.Date;
//获取类中的资源
public class Person extends Animal{
    private Integer id;
    String name;
    protected double money;
    public Date birthday;
    private  Person(){
        System.out.println("无参构造方法");
    }

    public Person(Integer id) {
        this.id = id;
        System.out.println("有参构造方法");
    }

    public void test1(){
        System.out.println("运行测试1 ");
    }
    private void test2(String name,Integer number){
        System.out.println("运行测试2 "+name+" "+number);
    }
    public int test3(int a,int b){
        System.out.println("运行测试3 "+a+" "+b);
        return a+b;
    }
    public static void main(String[] args) {
        //1.获取类对象
        Person p = new Person();
        Class<?> c = p.getClass();
        //2.通过class对象 获取类的资源
        String name = c.getName();
        System.out.println("全类名："+name);
        String simpleName = c.getSimpleName();
        System.out.println("类名："+simpleName);
        String superName = c.getSuperclass().getSuperclass().getName();
        System.out.println("超类："+superName);
        System.out.println("--------获取属性Filed---------");
        //可以获取类中的所以属性 但是不包括父类
        Field[] fs = c.getDeclaredFields();
        for (Field f:fs){
            //f就是类中的每个属性
            String fieldName = f.getName();
            Class type = f.getType();
            System.out.println("属性名："+fieldName+" 类型："+type);
        }
        System.out.println("------------------------------");
        //只能获取类中的公开资源(自己的和父类的...)
        Field[] fs2 = c.getFields();
        for (Field f:fs2){
            String fieldName = f.getName();
            Class type = f.getType();
            System.out.println("属性名："+fieldName+" 类型："+type);
        }
    }
}
class Animal{
    private int height;
    int age;
    protected String sex;
    public String address;
}
